package com.zqwh.yj.sdk.utils;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

/**
 * Created by eason.yang on 2018/5/2.
 */
public class PhoneInfoUtils {
    private TelephonyManager mTelephonyManager;

    public PhoneInfoUtils(Context context, PhoneStateListener listener) {
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        mTelephonyManager.listen(listener, PhoneStateListener.LISTEN_SERVICE_STATE
                        | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
                        | PhoneStateListener.LISTEN_DATA_ACTIVITY
                        | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
    }

    public String getIccid() {
        return mTelephonyManager.getSimSerialNumber();
    }

    public String getLineNumber(){
        return mTelephonyManager.getLine1Number();
    }

    //获取手机服务商信息
    public String getProviderName() {
        String providerName = "N/A";
        String netOperator = mTelephonyManager.getNetworkOperator();
        //IMSI号前面3位460是国家，紧接着后面2位00 02是中国移动，01是中国联通，03是中国电信。
        if (netOperator.equals("46000") || netOperator.equals("46002")) {
            providerName = "中国移动";//中国移动
        } else if (netOperator.equals("46001")) {
            providerName = "中国联通";//中国联通
        } else if (netOperator.equals("46003")) {
            providerName = "中国电信";//中国电信
        }
        return providerName;
    }
}
